﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Tayninh2011
{
    public sealed partial class FrmTnMain : RootForm
    {
        [DllImport("User32")]
        private static extern int SetForegroundWindow(IntPtr hwnd);
        [DllImportAttribute("User32.DLL")]
        private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        private static readonly FrmTnMain meForm = new FrmTnMain();
        FrmTnMap frmMap = FrmTnMap.CallMe;
        FrmTnMapTool frmMapTool = FrmTnMapTool.CallMe;
        FrmTnMapEditor frmMapEditor = FrmTnMapEditor.CallMe;
        FrmTnToolCash frmCash = FrmTnToolCash.CallMe;
        private FrmTnMain()
        {
            InitializeComponent();
            frmMap.MdiParent = this;
            
        }

        #region singleton

        public static FrmTnMain CallMe
        {
            get { return meForm; }
        }

        public new void Show()
        {
            if (isShown)
            {
                
                base.Show();
            }
            else
            {
                base.Show();
                
                isShown = true;
            }
        }
        private static bool isShown = false;

        static FrmTnMain()
        {

            meForm.FormClosing += new FormClosingEventHandler(frm_FormClosing);

        }
        private static void frm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            isShown = false;
            //meForm.Hide();
            if (MessageBox.Show("Bạn muốn thoát khỏi chương trình", "Thoát", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                
                Application.ExitThread();
                Application.Exit();
            }
        }

        #endregion singleton

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            
        }

        private void tsbOpenMap_Click(object sender, EventArgs e)
        {
            //Form7 frm7 = new Form7();
            //frm7.MdiParent = this;
            //frm7.Dock = DockStyle.Left;
            //frm7.Show();
            //Form8 frm8 = new Form8();
            //frm8.MdiParent = this;
            //frm8.Dock = DockStyle.Fill;
            //frm8.Show();

            
            frmMap.Dock = DockStyle.Fill;
            frmMap.Show();
            
            frmMapTool.BringToFront();
            frmMapTool.TopMost = true;
            frmMapTool.Show();
            
            frmMapEditor.Show();


        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            
        }

        private void tsbCalc_Click(object sender, EventArgs e)
        {
            frmCash.Show();
            
            
            //frmCash.ShowInTaskbar = false;
            //frmCash.TopMost = true;
            //frmCash.StartPosition = FormStartPosition.CenterScreen;
            
        }

        private void mnuMapTool_Click(object sender, EventArgs e)
        {
            frmMapTool.Show();
        }

        private void mnuMapEditor_Click(object sender, EventArgs e)
        {
            frmMapEditor.Show();
        }
    }
}
